package com.hns.can.master.web;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.web.BaseController;
import com.hns.can.master.service.WarnService;
import com.hns.tool.pub.DateTool;
import com.hns.tool.pub.PubUtil;
import com.hns.tool.pub.SearchConditionVo;

/**
 * 报警控制器
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
@Controller
@SessionAttributes({"SES_CURRENTUSER","SES_ORGANLIST", "SES_ROLELIST", "SES_AUTHORITY", "SES_THIRDMENU", "SES_ALLAUTHORITY"})
@RequestMapping("/warn")
public class WarnController extends BaseController {
    
    @Autowired
    private WarnService   warnService;
    
    /**
     * 获取警报灯的信息
     * @param request
     * @param response
     * @param map
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     */
    @SuppressWarnings("unchecked")
    @ResponseBody
    @RequestMapping("/getWarnLightInfo")
    public Object getWarnLightInfo(
        HttpServletRequest request, Map<String, Object> map) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        SearchConditionVo vo = new SearchConditionVo();
        List<String> orgIdlist = (List<String>)map.get("SES_ORGANLIST");
        if(PubUtil.isEmpty(orgIdlist)){
            return this.getReturnResult(dataMap);
        }
        
        //modidy by qianjy 2015-05-14
        SysUserEntity user = this.getCurrentUser().getUser();
        vo.setCorpId(user.getCorpId());
        
        vo.setOrgIds(orgIdlist);
        String currTime = DateTool.SHORT_DATE_FORMAT.format(new Date());
        vo.setBeginTime(currTime + " 00:00:00");
        vo.setEndTime(currTime + " 23:59:59");
        
        //获取当天故障
        int fault = warnService.getFaultCount(vo);
        int unsafeAction = warnService.getUnsafeActionCount(vo);
        int overSpeed = warnService.getOverSpeedCount(vo);
        dataMap.put("fault", fault);
        dataMap.put("unsafeAction", unsafeAction);
        dataMap.put("overSpeed", overSpeed);
        return this.getReturnResult(dataMap);
    }

}
